<template>
  <div class="hp_blog-list-box">
    <div class="hp_blog-list-search">
      <el-input v-model="query.keyWord" type="text" style="width: 200px;margin-right: 10px" size="mini" placeholder="请输入关键字"></el-input>
      <el-button type="primary" size="mini">搜索</el-button>
    </div>
    <el-table
      :data="blogList"
      stripe
      :height="800"
      style="width: 100%">
      <el-table-column prop="id" align="center" label="id" width="80px"></el-table-column>
      <el-table-column prop="user_name" align="center" label="创建用户" width="150"></el-table-column>
      <el-table-column prop="title" label="标题" width="200" show-overflow-tooltip></el-table-column>
      <el-table-column prop="intro" label="简介" width="300" show-overflow-tooltip></el-table-column>
      <el-table-column prop="create_time" align="center" label="创建日期">
        <template slot-scope="scope">{{$moment(new Date(scope.row.create_time)).format('YYYY-MM-DD')}}</template>
      </el-table-column>
      <el-table-column prop="create_time" align="center" label="更新日期">
        <template slot-scope="scope">
          {{scope.row.update_time ? $moment(new Date(scope.row.update_time)).format('YYYY-MM-DD') : '-'}}
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button @click="edit(scope.row)" type="text">编辑</el-button>
          <el-button @click="del(scope.row)" type="text">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {
  blogList,
  blogDel
} from '@/api/blog'
export default {
  name: 'blogList',
  data () {
    return {
      blogList: [],
      query: {
        pageNow: 1,
        pageSize: 20,
        keyWord: null
      }
    }
  },
  methods: {
    edit (row) {
      this.$router.push({
        path: '/main/addBlog',
        query: {
          id: row.id
        }
      })
    },
    async del (row) {
      this.$confirm('是否确定删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        await blogDel({
          id: row.id
        })
        this.$message.success('删除成功')
        this.getBlogList()
      }).catch()
    },
    async getBlogList () {
      this.blogList = await blogList(this.query)
    }
  },
  created () {
    this.getBlogList()
  }
}
</script>

<style scoped lang="stylus">
.hp_blog-list-box{
  width 100%
  .hp_blog-list-search{
    width 100%
    display flex
    align-items center
    justify-content flex-end
    margin-bottom 20px
  }
}
</style>
